import { ref } from "vue";
// import { useMapApi } from "@/utils/useMapApi";

export function useMapConfig(mapDom, lng, lat, radius, currentLng, currentLat) {
  console.log(mapDom);
  let map = ref(null);
  // let lng = ref(119.627619);
  // let lat = ref(29.065449);
  // let currentLng = ref(0);
  // let currentLat = ref(0);
  // let radius = ref(500);
  let marker = ref(null);
  let currentMarker = ref(null);
  let circle = ref(null);
  // let currentCircle = ref(null);s

  // onMounted(() => {
  initMap();
  // });

  // 初始化地图
  async function initMap() {
    // await useMapApi();
    //创建地图
    map.value = new window.AMap.Map(mapDom.value, {
      resizeEnable: true, //是否监控地图容器尺寸变化
      zoom: 15, //初始化地图层级
      center: [lng.value, lat.value], //初始化地图中心点
    });
    console.log(map);
    addMarker();
    addCircle();
  }

  // 添加标记
  function addMarker() {
    // console.log(this.currentForm.lat, this.currentForm.lng)
    marker.value = new window.AMap.Marker({
      position: new window.AMap.LngLat(lng.value, lat.value),
      // offset: new window.AMap.Pixel(-13, -30),
      title: "签到点",
    });

    currentMarker.value = new window.AMap.Marker({
      position: new window.AMap.LngLat(currentLng.value, currentLat.value),
      // offset: new window.AMap.Pixel(-13, -30),
      title: "当前所在位置",
    });

    map.value.add(currentMarker.value);

    map.value.add(marker.value);

    // this.currentMarker.on('click', this.markerCurrentClickHandle)
    // this.newMarker.on('click', this.markerNewClickHandle)
    // this.currentMarker.on('mousemove', this.markerCurrentMousemoveHandle)
  }

  // 移除标记
  // function removeMarker() {
  //   map.remove(marker);
  //   map.remove(currentMarker);
  // }

  // 添加圆
  function addCircle() {
    circle.value = new window.AMap.Circle({
      center: new window.AMap.LngLat(lng.value, lat.value), // 圆心位置
      radius: radius.value, //半径
      strokeColor: "#1791fc", //线颜色
      strokeOpacity: 1, //线透明度
      strokeWeight: 1, //线粗细度
      fillColor: "#1791fc", //填充颜色
      fillOpacity: 0.35, //填充透明度
    });

    // currentCircle = new window.AMap.Circle({
    //   center: new window.AMap.LngLat(this.newLng, this.newLat), // 圆心位置
    //   radius: this.currentForm.currentRadius, //半径
    //   strokeColor: '#ff3300', //线颜色
    //   strokeOpacity: 1, //线透明度
    //   strokeWeight: 1, //线粗细度
    //   fillColor: '#ff3300', //填充颜色
    //   fillOpacity: 0.35, //填充透明度
    // })

    // map.add(this.currentCircle)

    map.value.add(circle.value);

    // this.currentCircle.on('click', this.currentCircleClick)
    // this.newCircle.on('click', this.newCircleClick)
  }

  // 移除圆
  // function removeCircle() {
  //   // this.map.remove(this.newCircle)
  //   map.remove(currentCircle);
  // }

  // return {
  //   addMarker,
  //   removeMarker,
  //   addCircle,
  //   removeCircle,
  // };
}
